package com.hnkywl.sts.action.xsgl;

import com.google.gson.Gson;
import com.hnkywl.sts.dao.xsgl.XsdDao;
import com.hnkywl.sts.entity.cggl.Cgd;
import com.hnkywl.sts.entity.htgl.Cght;
import com.hnkywl.sts.entity.organ.Qyjg;
import com.hnkywl.sts.entity.sfgl.Sfk;
import com.hnkywl.sts.entity.sys.Bm;
import com.hnkywl.sts.entity.sys.Gncz;
import com.hnkywl.sts.entity.sys.Yg;
import com.hnkywl.sts.entity.xsgl.Xsd;
import com.hnkywl.sts.entity.xsgl.Xsmx;
import com.hnkywl.sts.service.cggl.CgdService;
import com.hnkywl.sts.service.organ.QyjgService;
import com.hnkywl.sts.service.sys.GnczService;
import com.hnkywl.sts.service.sys.YgService;
import com.hnkywl.sts.service.xsgl.XsdService;
import com.hnkywl.sts.util.CalcUtils;
import com.hnkywl.sts.util.DocumentHandler;
import com.hnkywl.sts.util.POIUtil;
import com.hnkywl.sts.util.ReflectionUtils;
import jxl.Sheet;
import jxl.Workbook;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Namespaces;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: jerry
 * Date: 13-4-15
 * Time: 下午2:17
 * To change this template use File | Settings | File Templates.
 */
@Namespaces({@Namespace("/xsgl/xsdgl"), @Namespace("/xsgl/xsdtz")})
public class XsdAction extends SimpleActionSupport {
    private XsdService xsdService;
    private CgdService cgdService;
    private QyjgService qyjgService;
    private XsdDao xsdDao;

    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows;
    //销售单ID
    private Long xsdId;
    //销售单
    private Xsd xsd;

    private Cgd cgd;
    //当前登录员工的公司ID
    private Long gsId;
    private Long zggsId;
    private Long zgjgId;
    private Yg yg;

    private Date startDate;

    private Date datetime;

    private String ewmtime;
    //查询条件
    private Long xshtId;

    private String cxzt;

    private String zt;

    private String jszt;

    private String xsdh;

    private Long khId;

    private Long xsgsId;

    private Long sbdwId;

    private Long sbgsId;

    private Long sbbmId;

    private Long sbrId;

    private Long gcId;

    private String gcmc;

    private Date fhsjStart;

    private Date fhsjEnd;

    private Long xsjsdId;

    private String sftzd;

    private Bm xsdhm;
    private String ewmType;
    private Date currentTime = new Date();
    private String zdr;
    //配送单号
    private String psdh;
    //库存零售客户
    private Qyjg qyjg;
    //库存零售客户Id
    private Long qyjgId;
    //二级单位Id
    private String erdwMc;

    private Boolean dlkhxsd = true;

    //功能操作
    private List<Gncz> gnczList;
    private GnczService gnczService;
    private String xslx;
    private String pszt;
    private String xspsKh;
    private Long thckId;

    private String khIds;

    private String htbmStr;

    private String comType;

    private String zh;
    private String lsh;
    private String thrs;
    private String jbr;
    private String sfzhm;
    private String cars;
    private String year;
    private String month;
    private String day;
    private File upload;
    private String xhtbm;
    private String wjsdlf;
    private String wjstx;
    private String sumDlfTx;
    private String sfkIds;
    private String zjzyje;
    private String zjzff;
    private String httx;
    // 保证金是否充当代理费
    private Boolean bzjsfdlf = false;
    private Boolean sftg;
    private String dqtxxx;
    private Cght cght;
    private String zdlf;
    private String ztx;

    private Double htce;
    private Boolean sfkzdlf = false;

    /**
     * 方法名:     销售单查询
     * 功能描述:      销售单查询
     * 输入参数:    <@param cglx 采购合同类型 采购入库，直达到货>
     * 异常:      <RuntimeException  Exception>
     * 创建人:     lingyun
     * 创建日期:   13-3-7上午11:47
     * 修改人:     lingyun
     * 修改日期:   13-3-7上午11:47
     */
    @Action("xsdList")
    public void xsdList() throws ParseException {
//        if (sbdwId != null) {
//            Gsjg g = this.gsjgService.findGsjgDetail(sbdwId);
//            if (g instanceof Nbgs) {
//                sbgsId = sbdwId;
//            } else {
//                sbbmId = sbdwId;
//            }
//            this.renderJson(this.xsdService.findAllXsd(xsdh, fhsjStart, fhsjEnd, xshtId, khId, gcmc, sbgsId, sbbmId, sbrId, zt, sftzd, page, rows));
//        } else {
        this.renderJson(this.xsdService.findAllXsd(xsdh, fhsjStart, fhsjEnd, xshtId, khId, gcId, sbgsId, sbbmId, sbrId, zt, cxzt, sftzd, null, dlkhxsd, 1, page, rows));
//        }
    }

    /**
     * 销售合同 销售记录查询
     *
     * @throws ParseException
     */
    @Action("xsdByXshtList")
    public void xsdByXshtList() throws ParseException {
//        if (sbdwId != null) {
//            Gsjg g = this.gsjgService.findGsjgDetail(sbdwId);
//            if (g instanceof Nbgs) {
//                sbgsId = sbdwId;
//            } else {
//                sbbmId = sbdwId;
//            }
//            this.renderJson(this.xsdService.findAllXsd(xsdh, fhsjStart, fhsjEnd, xshtId, khId, gcmc, sbgsId, sbbmId, sbrId, zt, sftzd, page, rows));
//        } else {
        this.renderJson(this.xsdService.findXsdByXsht(xsdh, fhsjStart, fhsjEnd, xshtId, khId, gcId, sbgsId, sbbmId, sbrId, zt, cxzt, sftzd, null, dlkhxsd, page, rows));
//        }
    }

    /**
     * 方法名:     销售单查询
     * 功能描述:      销售单查询
     * 输入参数:    <@param cglx 采购合同类型 采购入库，直达到货>
     * 异常:      <RuntimeException  Exception>
     * 创建人:     lingyun
     * 创建日期:   13-3-7上午11:47
     * 修改人:     lingyun
     * 修改日期:   13-3-7上午11:47
     */
    @Action("xsdexamineList")
    public void xsdexamineList() throws ParseException {
        this.renderJson(this.xsdService.findAllXsd(xsdh, fhsjStart, fhsjEnd, xshtId, khId, gcId, sbgsId, sbbmId, sbrId, zt, cxzt, sftzd, "kcls", null, 1, page, rows));
    }

    /**
     * 出库管理
     *
     * @return
     */
    @Actions({@Action("xsdgl"), @Action("xsdexamine")})
    public String xsdgl() {
        fhsjStart = sDaysAfterNowDate(7);
        fhsjEnd = sDaysAfterNowDate(0);
        gnczList = gnczService.findGnczByJsAndUrl(request.getServletPath());
        return SUCCESS;
    }

    @Action("search_XshtCorKh")
    public String search_XshtCorKh() {
        return SUCCESS;
    }

    /**
     * 过户出库
     *
     * @return`
     */
    @Action("ckgl")
    public String ckgl() {
        fhsjStart = sDaysAfterNowDate(7);
        fhsjEnd = sDaysAfterNowDate(0);
        gnczList = gnczService.findGnczByJsAndUrl(request.getServletPath());
        return SUCCESS;
    }

    /**
     * 过户出库
     *
     * @throws ParseException
     */
    @Action("ghckList")
    public void ghckList() throws ParseException {
        this.renderJson(this.xsdService.findAllXsd(xsdh, fhsjStart, fhsjEnd, xshtId, khId, gcId, sbgsId, sbbmId, sbrId, zt, cxzt, sftzd, null, dlkhxsd, 2, page, rows));
    }

    /**
     * 配款管理
     *
     * @return
     */
    @Action("pkgl")
    public String pkgl() {
        fhsjStart = sDaysAfterNowDate(7);
        fhsjEnd = sDaysAfterNowDate(0);
        gnczList = gnczService.findGnczByJsAndUrl(request.getServletPath());
        return SUCCESS;
    }

    /**
     * 配款管理
     *
     * @throws ParseException
     */
    @Action("pkglList")
    public void pkglList() throws ParseException {
        this.renderJson(this.xsdService.findAllXsd(xsdh, fhsjStart, fhsjEnd, xshtId, khId, gcId, sbgsId, sbbmId, sbrId, zt, cxzt, sftzd, null, dlkhxsd, 3, page, rows));
    }

    //   当前日期加减n天后的日期，返回String   (yyyy-mm-dd)
    private Date sDaysAfterNowDate(int n) {
        Calendar rightNow = Calendar.getInstance();
        rightNow.add(Calendar.DAY_OF_MONTH, -n);
        return rightNow.getTime();
    }

    @Action("xsdtzApply")
    public void xsdtzApply() {
        try {
            this.xsdService.xsdtzApply(xsdId);
            renderText("{\"statusCode\":\"200\", \"message\":\"申请销售单调整成功\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("xsdtzCancel")
    public void xsdtzCancel() {
        try {
            this.xsdService.xsdtzCancel(xsdId);
            renderText("{\"statusCode\":\"200\", \"message\":\"取消销售采购单调整成功\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("xsdtzExamine")
    public void xsdtzExamine() {
        try {
            this.xsdService.xsdtzExamine(xsdId);
            renderText("{\"statusCode\":\"200\", \"message\":\"审批销售单调整成功\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("save_print_elements")
    public void savePrintElements() {
        try {
            this.xsdService.saveXsdPrintElements(xsdId, zh, lsh, thrs, jbr, sfzhm, cars, year, month, day);
            renderText("{\"statusCode\":\"200\", \"message\":\"保存成功!\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("xsdtz")
    public String xsdtz() {
        currentTime = new Date();
        gnczList = gnczService.findGnczByJsAndUrl(request.getServletPath());
        return SUCCESS;
    }

    @Action("xsdSearchList")
    public void xsdSearchList() {
        this.renderJson(this.xsdService.findXsdSearch(xsdh, fhsjStart, fhsjEnd, xsjsdId, xsgsId, sbgsId, khId, page, rows, erdwMc, htbmStr, xhtbm));
    }

    @Action("xsdSearchDateList")
    public void xsdSearchDateList() {
        this.renderJson(this.xsdService.findXsdSearchDate(xsdh, fhsjStart, fhsjEnd, xsjsdId, xsgsId, sbgsId, khId, page, rows, erdwMc));
    }


    @Action("computerprice")
    public void computerPrice() {
        this.renderText(this.xsdService.computerPrice(khIds));
    }

    @Action("xsdXspsList")
    public void xsdXspsList() {
        this.renderJson(this.xsdService.findAllXsdNotFyzr(thckId, xspsKh, sbgsId, pszt, xsdh, psdh, page, rows));
    }

    @Action("xsdgl_xsmx")
    public void xsmxDetail() {
        this.renderJson(this.xsdService.findXsmxDetail(xsdId));
    }

    @Action("xsdgl_js_xsmx")
    public void xsmxJsDetail() {
        this.renderJson(this.xsdService.findXsmxJsDetail(xsdId));
    }

    @Action("xsdgl_xsfy")
    public void xsfyDetail() {
        this.renderJson(this.xsdService.findXsfyDetail(xsdId));
    }

    /**
     * 挂款明细
     */
    @Action("xsdgkmx")
    public void xsdgkmx() {
        this.renderJson(this.xsdService.findXsdgkmx(xsdId));
    }

    /**
     * 计费明细
     */
    @Action("xsdgl_jfmx")
    public void jfmxDetail() {
        this.renderJson(this.xsdService.findJfmxDetail(xsdId));
    }

    @Action("xsd_xslx")
    public String xsdglXslx() {
        zgjgId = YgService.getCurrentYgGsId();

        return SUCCESS;
    }


    @Actions({@Action("sdxk_content"), @Action("xsdgl_content"), @Action("xsdgl_detail"), @Action("xsdgk_detail"), @Action("xsdpk_detail"), @Action("xsdgl_examine"), @Action("xsdtz_content"), @Action("xsdtz_detail"), @Action("xsdexamine_detail"), @Action("xsd_cbjgtz")})
    public String xshtContent() {
        try {
            currentTime = new Date();
            zdr = YgService.getCurrentYgName();
            yg = YgService.getCurrentYg();
            gsId = YgService.getCurrentYgGsId();
            zggsId = YgService.getCurrentYgZgGsId();
            if (xsdId != null) {
                xsd = this.xsdService.findXsdDetail(xsdId);
                cght = xsd.getXsht().getZddhcght();
                // 查询通知单上客户信息
                Map tzsMap = this.xsdService.findXsdTzdInfo(xsd.getKh().getId());
                if (null != tzsMap && null != xsd.getSfzhm() && StringUtils.isBlank(xsd.getSfzhm())) {
                    if (null != tzsMap.get("ZH")) {
                        xsd.setZh(tzsMap.get("ZH").toString());
                    }
                    if (null != tzsMap.get("LSH")) {
                        xsd.setLsh(tzsMap.get("LSH").toString());
                    }

                    if (null != tzsMap.get("THRS")) {
                        xsd.setThrs(tzsMap.get("THRS").toString());
                    }

                    if (null != tzsMap.get("JBR")) {
                        xsd.setJbr(tzsMap.get("JBR").toString());
                    }

                    if (null != tzsMap.get("SFZHM")) {
                        xsd.setSfzhm(tzsMap.get("SFZHM").toString());
                    }

                    if (null != tzsMap.get("CARS")) {
                        xsd.setCars(tzsMap.get("CARS").toString());
                    }
                }

                // 查询总的代理费和贴息
                Map zDlfTxMap = this.xsdService.findMapDlfOrTx(xsd);
                // 未付款的代理费
                Map wfkDlfMap = this.xsdService.findMapWfkDlfOrTx(xsd);

                // 查询资金使用情况
                List<Map> hthkMapList = this.xsdService.findMapHthk(xsd);

                if (xsd.getXsht().getZddhcght().getBzjfs().equals(0)) {
                    zdlf = zDlfTxMap.get("DLFJE").toString();
                    ztx = zDlfTxMap.get("TXJE").toString();
                    wjsdlf = wfkDlfMap.get("DLFJE").toString();
                    // 判断使用多少承兑和现金
                    if (null != hthkMapList && hthkMapList.size() > 0) {
                        wjstx = hthkMapList.get(0).get("HTHK").toString() + "(元：现金)；" + hthkMapList.get(1).get("HTHK").toString() + "(元：承兑)";
                    } else {
                        wjstx = 0 + "(元：现金)；" + 0 + "(元：承兑)";
                    }
                    sumDlfTx = String.valueOf(CalcUtils.round(Double.valueOf(wjsdlf), 2));
                    Double zj = CalcUtils.round(this.xsdService.findZjzyje(xsd) - xsd.getHszje(), 2);
                    zjzyje = zj.toString();
                } else {
                    wjsdlf = "0";
                    wjstx = "0";
                    sumDlfTx = "0";
                }
                jszt = this.xsdService.findXsdJszt(xsd);
                if (xsd.getXslx() != null && xsd.getXslx().equals("zddh")) {
                    cgd = this.cgdService.findCgdByXsd(xsdId);
                }
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
                if (xsd != null) {
                    ewmtime = simpleDateFormat.format(xsd.getLastUpdated());
                } else {
                    ewmtime = "";
                }
            } else {
                startDate = new Date(); //当前日期
                Calendar calendar = Calendar.getInstance();//日历对象
                calendar.setTime(startDate);//设置当前日期
                calendar.add(Calendar.MONTH, 1);//将当前日期加一个月
                datetime = calendar.getTime();//输出格式化的日期
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return SUCCESS;
    }

    /**
     * 新增库存零售客户的跳转页面
     *
     * @return
     */
    @Action("kclskh_content")
    public String kclskhContent() {
        if (qyjgId != null) {
            qyjg = this.qyjgService.findQyjgDetail(qyjgId);
        } else {
            qyjg = new Qyjg();
        }
        return SUCCESS;
    }

    /**
     * 方法名:     保存采购合同
     * 功能描述:      保存数据库采购合同
     * 输入参数:    <@param cght 采购合同>
     * 异常:      <RuntimeException  Exception>
     * 创建人:     lingyun
     * 创建日期:   13-3-7上午11:47
     * 修改人:     lingyun
     * 修改日期:   13-3-7上午11:47
     */
    @Action("add_xsd")
    public void addXsd() {
        try {
            initXsd(xsd);
            this.xsdService.saveXsd(xsd);
            renderText("{\"statusCode\":\"200\", \"message\":\"保存销售单成功\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 方法名:     保存销售单
     * 功能描述:      保存数据库采购合同
     * 输入参数:    <@param cght 采购合同>
     * 异常:      <RuntimeException  Exception>
     * 创建人:     lingyun
     * 创建日期:   13-3-7上午11:47
     * 修改人:     lingyun
     * 修改日期:   13-3-7上午11:47
     */
    @Action("edit_xsd")
    public void editXsd() {
        try {
            List<Xsmx> mxList = this.xsdService.getXsmx(xsd.getId());
            Xsd clone = this.xsdService.findXsdDetail(xsd.getId());
            String xsdbm = clone.getXsdh();
            ReflectionUtils.getInstance(clone, xsd);
            initXsd(clone);
            this.xsdService.editXsd(clone, xsdbm, mxList);
            //this.ewmService.createQRCode(xsd.getId() + "-" + xsd.getLastUpdated(), xsd.getId(), xsd.getClass().getSimpleName());
            renderText("{\"statusCode\":\"200\", \"message\":\"保存销售单成功\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 成本价格调整
     */
    @Action("xsd_cbjgtz_save")
    public void cbjgtz() {
        try {
            xsdService.cbjgtz(xsd);
            renderText("{\"statusCode\":\"200\", \"message\":\"保存成功\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 方法名:     冲销销售单
     * 功能描述:      保存数据库采购合同
     * 输入参数:    <@param cght 采购合同>
     * 异常:      <RuntimeException  Exception>
     * 创建人:     lingyun
     * 创建日期:   13-3-7上午11:47
     * 修改人:     lingyun
     * 修改日期:   13-3-7上午11:47
     */
    @Action("edit_xsdtz")
    public void editXsdtz() {
        try {
            Xsd yxsd = this.xsdService.findXsdDetail(xsd.getId());
            if (yxsd != null && yxsd.getSftzd()) {
                throw new RuntimeException("此销售单已冲销，无需再次冲销!");
            }
            List<Xsmx> xsmxList = xsd.getXsmxList();
            ReflectionUtils.getInstance(xsd, yxsd);
            initXsd(xsd);
            Xsd hcxsd = new Xsd();
            ReflectionUtils.getInstance(hcxsd, yxsd);
            initXsd(hcxsd);
            this.xsdService.editXsdtz(xsd, xsmxList, hcxsd, yxsd);
            //this.ewmService.createQRCode(xsd.getId() + "-" + xsd.getLastUpdated(), xsd.getId(), xsd.getClass().getSimpleName());
            renderText("{\"statusCode\":\"200\", \"message\":\"调整销售单成功\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("transfer_xsd")
    public void transfer_xsd() {
        try {
            this.cgdService.transferXsd(xsdId);
            renderText("{\"statusCode\":\"200\", \"message\":\"同步销售单成功\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }

    }

    /**
     * 审核出库单
     */
    @Action("examine_xsd")
    public void examine_xsd() {
        try {
            this.xsdService.examineXsd(xsdId);
            renderText("{\"statusCode\":\"200\", \"message\":\"审核销售单成功\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 挂款审核
     *
     * @return
     */
    @Action("gksh")
    public String gksh() {
        return SUCCESS;
    }

    /**
     * 挂款金额审核，保存结果
     */
    @Action("gksh_saveItem")
    public void gksh_saveItem() {
        try {
            if (null != sftg && sftg) {
                this.xsdService.gksh_saveItem(true, xsdId);
                renderText("{\"statusCode\":\"200\", \"message\":\"审核通过成功！\"}");
            } else {
                this.xsdService.gksh_saveItem(false, xsdId);
                renderText("{\"statusCode\":\"200\", \"message\":\"审核不通过成功！\"}");
            }

        } catch (Exception e) {
            renderText("{\"statusCode\":\"300\", \"message\":\"系统异常！\"}");
        }
    }


    /**
     * 计算当前代理费和贴息
     */
    @Action("jsDlfTx")
    public void jsDlfTx() {
        List<Map<Long, Double>> mapList = null;
        try {
            Xsd xsdItem = xsdService.findXsdDetail(xsdId);//查出销售单
            mapList = this.xsdService.jsGk(xsdItem, sfkIds);
            this.xsdService.executeDqTxAndDlf(xsdItem);
            Map map = this.xsdService.findDqDlfOrTx(xsdItem);
            this.xsdService.dealDate(xsdId, mapList);
            renderText("{\"statusCode\":\"200\", \"dqdlf\":\"" + map.get("DLFJE") + "\", \"dqtx\":\"" + map.get("TXJE") + "\"}");
        } catch (Exception e) {
            this.xsdService.dealDate(xsdId, mapList);
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }

    }


    // 挂款
    @Action("xsdgl_sfkpk")
    public void sfkpk_xsd() {
        Xsd xsdItem = xsdService.findXsdDetail(xsdId);
        List<Sfk> sfkList;
        List<Map<Long, Double>> tempList = null;
        try {
            Cght cght = xsdItem.getXsht().getZddhcght();
            if (!xsdItem.getZt().equals("ygk")) {
                // 判断是否是最后一次赎货，并判断是否解锁保证金
                Boolean hasEnd = this.xsdService.checkLastCondition(xsdId);
                if (hasEnd && cght.getBzjfs() != 2) {
                    if (cght.getHtms().equals("xsms")) {
                        throw new RuntimeException("已经是最后一次赎货，请解锁保证金!");
                    } else if (cght.getZt().equals("yly") || cght.getZt().equals("yzz")) {
                        throw new RuntimeException("已经是最后一次赎货，请解锁保证金!");
                    }
                }
                if (cght.getBzjfs() == 0) {//一次性使用
                    sfkList = this.xsdService.getGkSfk(xsd);
                    tempList = this.xsdService.copyGkSfk(xsd);
                    // 挂款操作
                    String result = this.xsdService.gkOnetimeBond(xsdItem, sfkList);
                    if (result.equals("0")) {
                        // 扣除代理费
                        this.xsdService.dealDlfInfo(xsdItem, sfkList, tempList, bzjsfdlf, sfkzdlf);
                        renderText("{\"statusCode\":\"200\", \"message\":\"挂款成功，可以放货!\"}");
                    } else {
                        renderText("{\"statusCode\":\"300\", \"message\":\"" + result + "\"}");
                    }

                } else if (cght.getBzjfs() == 1) {//按比例使用
                    // 判断是否满足放货,并进行挂款
                    String result = this.xsdService.gkProRataBond(xsdItem, xsd);
                    if (result.equals("success")) {
                        renderText("{\"statusCode\":\"200\", \"message\":\"按比例释放方式挂款成功，可以放货!\"}");
                    } else {
                        renderText("{\"statusCode\":\"300\", \"message\":\"" + result + "\"}");
                    }
                } else {//无保证金
                    // 判断是否满足放货，如果满足进行挂款
                    String result = this.xsdService.gkNoBond(xsdItem, xsd);
                    if (result.equals("success")) {
                        renderText("{\"statusCode\":\"200\", \"message\":\"无保证金赎货挂款成功，可以放货!\"}");
                    } else {
                        renderText("{\"statusCode\":\"300\", \"message\":\"" + result + "\"}");
                    }
                }
            } else {
                renderText("{\"statusCode\":\"300\", \"message\":\"已经挂款成功!\"}");
            }
        } catch (Exception e) {
            if (null != tempList) {
                this.xsdService.dealDate(xsdId, tempList);
            }
            renderText("{\"statusCode\":\"300\", \"message\":\"挂款异常：" + e.getMessage() + "\"}");
        }
    }


    @Action("xsdgl_sfktk")
    public void xsdgl_sfktk() {
        try {
            Xsd xsdItem = xsdService.findXsdDetail(xsdId);
            this.xsdService.saveXsdtk(xsdItem, xsd, htce);
            renderText("{\"statusCode\":\"200\", \"message\":\"退款成功\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 配款
     */
    @Action("xsdgl_pk")
    public void xsdglPk() {
        try {
            Xsd xsdItem = xsdService.findXsdDetail(xsdId);
            Qyjg kh = qyjgService.findQyjgDetail(xsdItem.getKh().getId());
            Cght cght = xsdItem.getXsht().getZddhcght();
            if (cght.getBzjfs() == 0) {//一次性使用配款
                //校验是否后定价
                this.xsdService.executeActualPrice(xsdId);
                this.xsdService.oneTimeAllocatePay(xsdItem);
                renderText("{\"statusCode\":\"200\", \"message\":\"配款成功!\"}");
            } else if (cght.getBzjfs() == 1) {//按比例使用
                //校验是否后定价
                this.xsdService.executeActualPrice(xsdId);
                // 配款操作
                String pkResult = this.xsdService.proRataAllocatePay(xsdItem);
                if (pkResult.equals("0")) {
                    renderText("{\"statusCode\":\"200\", \"message\":\"按比例释放方式配款成功!\"}");
                } else {
                    renderText("{\"statusCode\":\"300\", \"message\":\"按比例释放方式配款失败!\"}");
                }
            } else {// 无保证金
                //校验是否后定价
                this.xsdService.executeActualPrice(xsdId);
                // 配款操作
                String pkReslut = this.xsdService.noBondAllocatePay(xsdItem, kh);
                if (StringUtils.equals(pkReslut, "0")) {
                    renderText("{\"statusCode\":\"200\", \"message\":\"无保证金情况配款成功!\"}");
                } else if (StringUtils.equals(pkReslut, "1")) {
                    renderText("{\"statusCode\":\"300\", \"message\":\"无保证金情况配款失败，收付款金额不够!\"}");
                } else {
                    renderText("{\"statusCode\":\"300\", \"message\":\"配款异常!\"}");
                }
            }
            this.xsdService.updateClxxZtForXsmx(xsdItem);
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("cancelexamine_xsd")
    public void cancelexamine_xsd() {
        try {
            this.xsdService.cancelexamineXsd(xsdId);
            renderText("{\"statusCode\":\"200\", \"message\":\"取消审核销售单成功\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    //销售结算单中查询销售单
    @Action("xsdmxSearchList")
    public void xgdmxSearchList() {
        this.renderJson(this.xsdService.findXsdmxSearch(xsjsdId));
    }

    @Action("jsmxExp")
    public String jsmxExp() {
        Map<String, Object> map = this.xsdService.findXsdmxExp(xsjsdId);
        List<Map> xsmxList = (List<Map>) map.get("rows");
        //第一步，创建一个webbook，对应一个Excel文件
        HSSFWorkbook wb = new HSSFWorkbook();
        //第二步，在webbook中添加一个sheet,对应Excel文件中的sheet
        HSSFSheet sheet = wb.createSheet("sheet1");
        POIUtil poiUtil = new POIUtil(wb);
        //设置列宽
        sheet.setDefaultRowHeightInPoints(21);
        sheet.setDefaultColumnWidth((short) 20);
        //第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
        HSSFCellStyle headerStyle = poiUtil.createHeader3HSSFCellStyle(wb);
        //生成第一行数据
        poiUtil.fillRow(sheet, headerStyle, 0, "销售单号", "下级单位", "物资编码", "物资名称", "规格型号", "长宽", "单位", "数量", "含税价(元)", "不含税价(元)",
                "净额(元)", "税额(元)");
        //表体部分
        for (int i = 1; i < xsmxList.size() + 1; i++) {
            Map item = xsmxList.get(i - 1);
            poiUtil.fillRow(sheet, null, i, item.get("xsdh"), item.get("gc.mc"), item.get("wzgg.code"), item.get("wzgg.name"), item.get("wzgg.ggxh"), item.get("ck"),
                    item.get("wzgg.dw"), item.get("cksl"), item.get("hsj"), item.get("bhsj"), item.get("je"),
                    item.get("se"));
        }
        Map sumItem = (Map) map.get("sum");
        HSSFCellStyle sumStyle = wb.createCellStyle();
        HSSFFont font = wb.createFont();
        font.setColor(HSSFFont.COLOR_RED);
        sumStyle.setFont(font);
        poiUtil.fillRow(sheet, sumStyle, xsmxList.size() + 1, "代垫运费:", sumItem.get("ddyf"), "", "", "", "", "净额:", sumItem.get("je"), "税额:",
                sumItem.get("se"), "面额:", sumItem.get("me"));
        try {
            response.setContentType("application/x-download");
            String filedisplay = new String(("销售结算明细.xls").getBytes("gb2312"), "iso8859-1");
            response.addHeader("Content-Disposition", "attachment;filename=" + filedisplay);
            wb.write(response.getOutputStream());
            response.getOutputStream().close();
        } catch (Exception e) {
            e.printStackTrace();
            renderText("位置异常，导出失败" + e.getMessage());
        }
        return null;
    }

    @Action("xsdmxSearchDetailList")
    public void xgdmxSearchDetailList() {
        this.renderJson(this.xsdService.findXsdmxSearchDetail(xsjsdId));
    }

    private void initXsd(Xsd xsd) {
        if (xsd.getXsht() != null && xsd.getXsht().getId() == null) {
            xsd.setXsht(null);
        }
        if (xsd.getLj() != null && xsd.getLj().getId() == null) {
            xsd.setLj(null);
        }
        if (xsd.getKh() != null && xsd.getKh().getId() == null) {
            xsd.setKh(null);
        }
        if (xsd.getThck() != null && xsd.getThck().getId() == null) {
            xsd.setThck(null);
        }
        if (xsd.getGc() != null && xsd.getGc().getId() == null) {
            xsd.setGc(null);
        }
        if (xsd.getFyzr() != null && xsd.getFyzr().getId() == null) {
            xsd.setFyzr(null);
        }
        if (xsd.getXsgs() != null && xsd.getXsgs().getId() == null) {
            xsd.setXsgs(null);
        }
        if (xsd.getXsbm() != null && xsd.getXsbm().getId() == null) {
            xsd.setXsbm(null);
        }
        if (xsd.getXsr() != null && xsd.getXsr().getId() == null) {
            xsd.setXsr(null);
        }
        if (xsd.getXbgs() != null && xsd.getXbgs().getId() == null) {
            xsd.setXbgs(null);
        }
        if (xsd.getXbbm() != null && xsd.getXbbm().getId() == null) {
            xsd.setXbbm(null);
        }
        if (xsd.getXsmxList() != null) {
            for (Xsmx xsmx : xsd.getXsmxList()) {

                if (xsmx.getJzfs() != null && xsmx.getJzfs().getId() == null) {
                    xsmx.setJzfs(null);
                }
                if (xsmx.getKh() != null && xsmx.getKh().getId() == null) {
                    xsmx.setKh(null);
                }
            }
        }
    }

    /**
     * 方法名:     提交销售单过户出库
     * 功能描述:      提交数据库销售单
     * 输入参数:    <@param xsdId 销售单ID>
     * 异常:      <RuntimeException  Exception>
     * 创建人:     lingyun
     * 创建日期:   13-3-7上午11:47
     * 修改人:     lingyun
     * 修改日期:   13-3-7上午11:47
     */
    @Action("commit_xsd")
    public void commit_xsd() {
        Xsd xsd = this.xsdService.findXsdDetail(xsdId);
        try {
            //提交出库单到仓储
            this.xsdService.commitXsd(xsd, comType);//transfer  self
            if (comType.equals("transfer")) {
                renderText("{\"statusCode\":\"200\", \"message\":\"过户成功!\"}");
            } else {
                renderText("{\"statusCode\":\"200\", \"message\":\"出库成功!\"}");
            }
//            Xsd xsd = this.xsdService.findXsdDetail(xsdId);
//            Boolean bool = this.xsdService.getXsdControlPd(xsd);
//            if (bool) {
//                this.xsdService.commitXsd(xsd);
//                renderText("{\"statusCode\":\"200\", \"message\":\"提交销售单成功\"}");
//            } else {
//                renderText("{\"statusCode\":\"300\", \"message\":\"该销售单已被质押，请解压后提交\"}");
//            }

        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("cancel_xsd")
    public void cancel_xsd() {
        try {
            Xsd xsd = this.xsdService.findXsdDetail(xsdId);
            if (xsd.getYck()) {
                renderText("{\"statusCode\":\"300\", \"message\":\"销售单已出库，无法取消提交\"}");
            } else {
                this.xsdService.cancel(xsd);
//            this.xsdService.calcKhSL(xsd, "add");
                renderText("{\"statusCode\":\"200\", \"message\":\"提交销售单成功\"}");
            }
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 方法名:     删除销售单
     * 功能描述:      删除数据库销售单
     * 输入参数:    <@param xsdId 销售单ID>
     * 异常:      <RuntimeException  Exception>
     * 创建人:     lingyun
     * 创建日期:   13-3-7上午11:47
     * 修改人:     lingyun
     * 修改日期:   13-3-7上午11:47
     */
    @Action("delete_xsd")
    public void delete_xsd() {
        try {
            Xsd xsd = this.xsdService.deleteXsd(xsdId);
//            this.flowService.delPorcessInstance(xy.getProcessInstanceId());
            renderText("{\"statusCode\":\"200\", \"message\":\"废除销售单成功\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("xsdKhList")
    public void xsdKhList() {
        this.renderJson(this.xsdService.findKhByXsd(xsgsId, sbgsId));
    }

    @Action("xsdKhById")
    public void xsdKhById() {
        this.renderJson(this.xsdService.findKhById(xsgsId));
    }


    /**
     * 打印
     */
    @Action("xsdDetail")
    public void xsdDetailforDY() {
        List<Map> xsdmxList = this.xsdDao.findXsmxList(xsdId);
        Integer js = 0;
        Double sbsl = 0d;
        Double se = 0d;
        java.text.DecimalFormat df = new java.text.DecimalFormat("0.0000");
        java.text.DecimalFormat jtdf = new java.text.DecimalFormat("0.00");
        StringBuffer sbTable = new StringBuffer();
        if (null != xsdmxList) {
            sbTable.append("<table id = \"xsdmxdetail\" class=\"tb intb\" style=\"text-align: center\"><thead>");
            sbTable.append("<tr>");
            sbTable.append("<td>品名</td><td>材质</td><td>钢卷号</td><td>规格</td>" +
                    "<td >件数</td><td>重量</td><td>合同号</td><td name=\"hsj_dy\">含税单价</td><td name=\"hse_dy\">含税额</td>");
            sbTable.append("</tr></thead><tbody>");

            for (int i = 0; i < xsdmxList.size(); i++) {
                sbTable.append("<tr>");
                //    品名
                sbTable.append("<td>");
                if (null != xsdmxList.get(i).get("wzgg.name")) {
                    sbTable.append(xsdmxList.get(i).get("wzgg.name"));
                }
                sbTable.append("</td>");
                //材质
                sbTable.append("<td>");
                if (null != xsdmxList.get(i).get("wzgg.cz")) {
                    sbTable.append(xsdmxList.get(i).get("wzgg.cz"));
                }
                sbTable.append("</td>");
                //钢卷号
                sbTable.append("<td>");
                if (null != xsdmxList.get(i).get("resource_serial_number_1")) {
                    sbTable.append(xsdmxList.get(i).get("resource_serial_number_1"));
                }
                sbTable.append("</td>");
                //  规格型号
                sbTable.append("<td>");
                if (null != xsdmxList.get(i).get("wzgg.ggxh")) {
                    sbTable.append(xsdmxList.get(i).get("wzgg.ggxh"));
                }
                sbTable.append("</td>");
                //件数
                sbTable.append("<td>");
                if (null != xsdmxList.get(i).get("js")) {
                    Integer mjs = (Integer) xsdmxList.get(i).get("js");
                    BigDecimal bjs = new BigDecimal(mjs);
                    Integer djs = bjs.setScale(4, BigDecimal.ROUND_HALF_UP).intValue();
                    sbTable.append(df.format(djs));
                    js += djs;
                }
                sbTable.append("</td>");

                // 重量
                sbTable.append("<td >");
                if (null != xsdmxList.get(i).get("sbsl")) {
                    Double msbsl = (Double) xsdmxList.get(i).get("sbsl");
                    BigDecimal bsbsl = new BigDecimal(msbsl);
                    Double dsbsl = bsbsl.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
                    sbTable.append(df.format(dsbsl));
                    sbsl += dsbsl;
                }
                sbTable.append("</td>");
                //合同号
                sbTable.append("<td>");
                if (null != xsdmxList.get(i).get("xsxt_xsdh")) {
                    sbTable.append(xsdmxList.get(i).get("xsxt_xsdh"));
                }
                sbTable.append("</td>");

                //单价(含税)
                sbTable.append("<td name=\"hsj_dy\"> ");
                if (null != xsdmxList.get(i).get("hsj")) {
                    sbTable.append(df.format(xsdmxList.get(i).get("hsj")));
                }
                sbTable.append("</td>");
                // 含税额
                sbTable.append("<td name=\"hse_dy\"> ");
                if (null != xsdmxList.get(i).get("hsj") && null != xsdmxList.get(i).get("sbsl")) {
                    Double mxscb = (Double) xsdmxList.get(i).get("hsj");
                    Double mcksbsl = (Double) xsdmxList.get(i).get("sbsl");
                    Double hse = (mxscb * mcksbsl);
                    BigDecimal bhsez = new BigDecimal(hse);
                    Double dbhsez = bhsez.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    sbTable.append(jtdf.format(dbhsez));
                    se += dbhsez;
                }
                sbTable.append("</td>");

                sbTable.append("</tr>");
            }
            sbTable.append("<tr>");

            sbTable.append("<td>合计:");
            sbTable.append("</td>");

            sbTable.append("<td>");
            sbTable.append("</td>");

            sbTable.append("<td>");
            sbTable.append("</td>");

            sbTable.append("<td>");
            sbTable.append("</td>");

            sbTable.append("<td >");
            sbTable.append(df.format(js));
            sbTable.append("</td>");

            sbTable.append("<td >");
            sbTable.append(df.format(sbsl));
            sbTable.append("</td>");

            sbTable.append("<td>");
            sbTable.append("</td>");

            sbTable.append("<td name=\"hsj_dy\">");
            sbTable.append("</td>");


            sbTable.append("<td name=\"hse_dy\">");
            sbTable.append(jtdf.format(se));
            sbTable.append("</td>");

            sbTable.append("</tr>");
            sbTable.append("</tbody></table>");
        }
        renderHtml(sbTable.toString());
    }


    /**
     * 套打
     */
    @Action("xsdDetailForTd")
    public void xsdDetailForTd() {
        Gson gson = new Gson();
        List<Map> xsdmxs = this.xsdDao.findXsmxListforTd(xsdId);
//        Integer js = 0;
//        Double sbsl = 0d;
//        Integer ckjs = 0;
//        Double cksl = 0d;
//        Double je = 0d;
        String result = "";
//        if (cgmxs.size() > 0) {
//            for (Map map : cgmxs) {
//                js += map.get("js") == null ? 0 : (Integer) map.get("js");
//                sbsl = sbsl + (map.get("sbsl") == null ? 0d : Double.parseDouble(map.get("sbsl").toString()));
//                hsj = hsj + (map.get("hsj") == null ? 0d : Double.parseDouble(map.get("hsj").toString()));
//                bhsj = bhsj + (map.get("bhsj") == null ? 0d : Double.parseDouble(map.get("bhsj").toString()));
//                rkjs = rkjs + (map.get("rkjs") == null ? 0 : Integer.parseInt(map.get("rkjs").toString()));
//                rksl = rksl + (map.get("rksl") == null ? 0d : Double.parseDouble(map.get("rksl").toString()));
//                rkjz = rkjz + (map.get("rkjz") == null ? 0d : Double.parseDouble(map.get("rkjz").toString()));
//            }
//            result = "{\"rows\":" + gson.toJson(cgmxs) + ",\"footer\":[{\"cd.id\":\"合计:\",\"js\":" + js
//                    + ",\"sbsl\":" + sbsl + ",\"hsj\":" + hsj + ",\"bhsj\":" + bhsj + ",\"rkjs\":" + rkjs + ",\"rksl\":" + rksl + ",\"rkjz\":" + rkjz + "}]}";
//        } else {
        result = gson.toJson(xsdmxs);
        //   }
        this.renderText(result);
    }

    @Action("xsdEwm")
    public void xsdEwm() {
        List<Map> xsdmxList = this.xsdDao.findXsmxList(xsdId);
        StringBuffer sbTable = new StringBuffer();
    }

    /**
     * 解质销售单
     */
    @Action("jz_xsd")
    public void jz_xsd() {
        try {
            Xsd xsd = this.xsdService.findXsdDetail(xsdId);
            Map<String, String> resultMap = this.xsdService.jzXsd(xsd);
            renderText("{\"statusCode\":\"" + resultMap.get("status") + "\", \"message\":\"" + resultMap.get("message") + "\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("sdxk_sfkList")
    public void sdxkSfkList() {
        Xsd xsd = xsdService.findXsdDetail(xsdId);
//        Qyjg kh = qyjgService.findQyjgDetail(xsd.getKh().getId());
        Cght cght = xsd.getXsht().getZddhcght();
        this.renderJson(this.xsdService.findXsdSkList(xsd, xsd.getKh().getId(), cght.getBzjfs(), cght.getHtms(), 1, 999999999));
    }


    /**
     * 导入
     */
    @Action("xsdmx_import")
    public void xsdmxImport() {
        try {
            Workbook book = Workbook.getWorkbook(upload);
            //  获得第一个工作表对象
            Sheet sheet = book.getSheet(0);
            //获取总行数
            int rows = sheet.getRows();
            StringBuffer sb = new StringBuffer();
            for (int i = 1; i < rows; i++) { //从第2行开始导入
                String bindNo = sheet.getCell(0, i).getContents().toString();//捆包号
                sb.append("\'" + bindNo + "\'" + ",");
            }
            sb = sb.deleteCharAt(sb.length() - 1);
            renderText(sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 导出模板
     *
     * @return
     */
    @Action("xsdmx_export")
    public String xsdmx_export() {
        //第一步，创建一个webbook，对应一个Excel文件
        HSSFWorkbook wb = new HSSFWorkbook();
        //第二步，在webbook中添加一个sheet,对应Excel文件中的sheet
        HSSFSheet sheet = wb.createSheet("sheet1");
        POIUtil poiUtil = new POIUtil(wb);
        //设置列宽
        sheet.setDefaultRowHeightInPoints(15);
        sheet.setDefaultColumnWidth((short) 12);
        sheet.setColumnWidth((short) 0, (short) (20 * 200));
        //第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
        HSSFRow row = sheet.createRow((int) 0);
        row.setHeightInPoints(36);
        //第四步，创建单元格，并设置值表头  设置表头居中
//        HSSFCellStyle titleStyle = poiUtil.createTitleHSSFCellStyle(wb);
//        HSSFCell titleCell = row.createCell((short) 0);
//        titleCell.setCellStyle(titleStyle);
//        titleCell.setEncoding(HSSFCell.ENCODING_UTF_16);
//        titleCell.setCellValue("攀钢物资明细导入模板");
//        sheet.addMergedRegion(new Region(0, (short) 0, 0, (short) 2));
        //生成第一行数据...表头
        HSSFCellStyle headerStyle = poiUtil.createHeader3HSSFCellStyle(wb);
        poiUtil.fillRow(sheet, headerStyle, 0, "捆包号");
        //生成从第二行开始的企业机构数据
        try {
            response.setContentType("application/x-download");
            String filedisplay = new String(("导入模板.xls").getBytes("gb2312"), "iso8859-1");
            response.addHeader("Content-Disposition", "attachment;filename=" + filedisplay);
            wb.write(response.getOutputStream());
            response.getOutputStream().close();
        } catch (Exception e) {
            e.printStackTrace();
            renderText("位置异常，导出失败" + e.getMessage());
        }
        return null;
    }

    @Action("exportWord")
    public void exportWord() throws IOException {
        try {
            Xsd xsd = this.xsdService.findXsdDetail(xsdId);
            SimpleDateFormat yearFomart = new SimpleDateFormat("yyyy");
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("zjm", xsd.getKh().getZjm());
            map.put("yy", yearFomart.format(new Date()));
            map.put("lsh", xsd.getLsh());
            map.put("zh", xsd.getZh());
            map.put("thr", xsd.getThr());
            map.put("jbr", xsd.getJbr());
            map.put("sfzhm", xsd.getSfzhm());
            map.put("qc", xsd.getKh().getQc());
            List<Map<String, Object>> newsList = new ArrayList<Map<String, Object>>();
            Double zjz = 0.0;
            Double zsl = 0.0;
            for (int i = 0; i < xsd.getXsmxList().size(); i++) {
                Xsmx xsmx = xsd.getXsmxList().get(i);
                Map<String, Object> mapTemp = new HashMap<String, Object>();
                mapTemp.put("xh", i + 1);
                mapTemp.put("dw", xsd.getKh().getJc());
                mapTemp.put("ht", xsmx.getXsxt_xsdh());
                mapTemp.put("pm", xsmx.getJtwz().getPm().getName());
                mapTemp.put("cz", xsmx.getJtwz().getCz());
                mapTemp.put("gg", xsmx.getJtwz().getGgxh());
                mapTemp.put("cp", xsmx.getCarNo());
                mapTemp.put("jz", xsmx.getSbsl());
                zjz += xsmx.getSbsl();
                mapTemp.put("sl", xsmx.getJs());
                zsl += xsmx.getJs();
                mapTemp.put("kb", xsmx.getBindNo());
                newsList.add(mapTemp);
            }
            map.put("newsList", newsList);
            map.put("zjz", zjz);
            map.put("zsl", zsl);
            map.put("jbrxm", xsd.getCreateUser().getXm());
            map.put("fhrxm", xsd.getShr().getXm());

            if (StringUtils.isBlank(xsd.getYear())) {
                map.put("year", yearFomart.format(new Date()));
            } else {
                map.put("year", xsd.getYear());
            }

            SimpleDateFormat monthFomart = new SimpleDateFormat("MM");
            if (StringUtils.isBlank(xsd.getMonth())) {
                map.put("month", monthFomart.format(new Date()));
            } else {
                map.put("month", xsd.getMonth());
            }

            SimpleDateFormat dayFomart = new SimpleDateFormat("dd");
            if (StringUtils.isBlank(xsd.getDay())) {
                map.put("day", dayFomart.format(new Date()));
            } else {
                map.put("day", xsd.getDay());
            }

            File file = null;
            InputStream fin = null;
            ServletOutputStream out = null;
            try {
                // 调用工具类WordGenerator的createDoc方法生成Word文档
                DocumentHandler dh = new DocumentHandler();
                file = dh.createDoc(map);
                fin = new FileInputStream(file);

                response.setCharacterEncoding("utf-8");
                response.setContentType("application/msword");
                // 设置浏览器以下载的方式处理该文件默认名为resume.doc
                // response.addHeader("Content-Disposition", "attachment;filename=thtzs.doc");
                response.addHeader("Content-Disposition", "attachment;filename=" + new String((xsd.getKh().getJc() + "提货通知书").getBytes("GB2312"), "iso8859-1") + ".doc");

                out = response.getOutputStream();
                byte[] buffer = new byte[512];  // 缓冲区
                int bytesToRead = -1;
                // 通过循环将读入的Word文件的内容输出到浏览器中
                while ((bytesToRead = fin.read(buffer)) != -1) {
                    out.write(buffer, 0, bytesToRead);
                }
            } finally {
                if (fin != null) fin.close();
                if (out != null) out.close();
                if (file != null) file.delete(); // 删除临时文件
            }
        } catch (Exception e) {
            renderText("导出失败" + e.getMessage());
        }
    }

    public String getGcmc() {
        return gcmc;
    }

    public void setGcmc(String gcmc) {
        this.gcmc = gcmc;
    }

    public String getXslx() {
        return xslx;
    }

    public void setXslx(String xslx) {
        this.xslx = xslx;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public Long getXsdId() {
        return xsdId;
    }

    public void setXsdId(Long xsdId) {
        this.xsdId = xsdId;
    }

    public Date getFhsjStart() {
        return fhsjStart;
    }

    public void setFhsjStart(Date fhsjStart) {
        this.fhsjStart = fhsjStart;
    }

    public Date getFhsjEnd() {
        return fhsjEnd;
    }

    public void setFhsjEnd(Date fhsjEnd) {
        this.fhsjEnd = fhsjEnd;
    }

    public Xsd getXsd() {
        return xsd;
    }

    public void setXsd(Xsd xsd) {
        this.xsd = xsd;
    }

    public Long getGsId() {
        return gsId;
    }

    public void setGsId(Long gsId) {
        this.gsId = gsId;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getDatetime() {
        return datetime;
    }

    public void setDatetime(Date datetime) {
        this.datetime = datetime;
    }

    public String getCxzt() {
        return cxzt;
    }

    public void setCxzt(String cxzt) {
        this.cxzt = cxzt;
    }

    public String getZt() {
        return zt;
    }

    public void setZt(String zt) {
        this.zt = zt;
    }

    public String getJszt() {
        return jszt;
    }

    public void setJszt(String jszt) {
        this.jszt = jszt;
    }

    public Long getXshtId() {
        return xshtId;
    }

    public void setXshtId(Long xshtId) {
        this.xshtId = xshtId;
    }

    public String getXsdh() {
        return xsdh;
    }

    public void setXsdh(String xsdh) {
        this.xsdh = xsdh;
    }

    public Long getKhId() {
        return khId;
    }

    public void setKhId(Long khId) {
        this.khId = khId;
    }

    public String getEwmtime() {
        return ewmtime;
    }

    public void setEwmtime(String ewmtime) {
        this.ewmtime = ewmtime;
    }

    public Long getGcId() {
        return gcId;
    }

    public void setGcId(Long gcId) {
        this.gcId = gcId;
    }

    public Yg getYg() {
        return yg;
    }

    public void setYg(Yg yg) {
        this.yg = yg;
    }

    public Long getZggsId() {
        return zggsId;
    }

    public void setZggsId(Long zggsId) {
        this.zggsId = zggsId;
    }

    public Long getXsjsdId() {
        return xsjsdId;
    }

    public void setXsjsdId(Long xsjsdId) {
        this.xsjsdId = xsjsdId;
    }

    public Bm getXsdhm() {
        return xsdhm;
    }

    public void setXsdhm(Bm xsdhm) {
        this.xsdhm = xsdhm;
    }

    public String getSftzd() {
        return sftzd;
    }

    public void setSftzd(String sftzd) {
        this.sftzd = sftzd;
    }

    public Qyjg getQyjg() {
        return qyjg;
    }

    public void setQyjg(Qyjg qyjg) {
        this.qyjg = qyjg;
    }

    public Long getQyjgId() {
        return qyjgId;
    }

    public void setQyjgId(Long qyjgId) {
        this.qyjgId = qyjgId;
    }

    public List<Gncz> getGnczList() {
        return gnczList;
    }

    public void setGnczList(List<Gncz> gnczList) {
        this.gnczList = gnczList;
    }

    public String getXspsKh() {
        return xspsKh;
    }

    public void setXspsKh(String xspsKh) {
        this.xspsKh = xspsKh;
    }

    public Date getCurrentTime() {
        return currentTime;
    }

    public String getPsdh() {
        return psdh;
    }

    public void setPsdh(String psdh) {
        this.psdh = psdh;
    }

    public void setCurrentTime(Date currentTime) {
        this.currentTime = currentTime;
    }

    public String getEwmType() {
        return ewmType;
    }

    public void setEwmType(String ewmType) {
        this.ewmType = ewmType;
    }

    public String getZdr() {
        return zdr;
    }

    public void setZdr(String zdr) {
        this.zdr = zdr;
    }

    public Long getXsgsId() {
        return xsgsId;
    }

    public void setXsgsId(Long xsgsId) {
        this.xsgsId = xsgsId;
    }

    public Long getSbdwId() {
        return sbdwId;
    }

    public void setSbdwId(Long sbdwId) {
        this.sbdwId = sbdwId;
    }

    public Long getSbgsId() {
        return sbgsId;
    }

    public void setSbgsId(Long sbgsId) {
        this.sbgsId = sbgsId;
    }

    public Long getSbbmId() {
        return sbbmId;
    }

    public void setSbbmId(Long sbbmId) {
        this.sbbmId = sbbmId;
    }

    public Long getSbrId() {
        return sbrId;
    }

    public void setSbrId(Long sbrId) {
        this.sbrId = sbrId;
    }

    public Long getZgjgId() {
        return zgjgId;
    }

    public void setZgjgId(Long zgjgId) {
        this.zgjgId = zgjgId;
    }

    public String getErdwMc() {
        return erdwMc;
    }

    public void setErdwMc(String erdwMc) {
        this.erdwMc = erdwMc;
    }

    public Cgd getCgd() {
        return cgd;
    }

    public void setCgd(Cgd cgd) {
        this.cgd = cgd;
    }

    public String getPszt() {
        return pszt;
    }

    public void setPszt(String pszt) {
        this.pszt = pszt;
    }

    public Long getThckId() {
        return thckId;
    }

    public void setThckId(Long thckId) {
        this.thckId = thckId;
    }

    public String getKhIds() {
        return khIds;
    }

    public void setKhIds(String khIds) {
        this.khIds = khIds;
    }

    public String gethtbmStr() {
        return htbmStr;
    }

    public void sethtbmStr(String htbmStr) {
        this.htbmStr = htbmStr;
    }

    public String getLsh() {
        return lsh;
    }

    public void setLsh(String lsh) {
        this.lsh = lsh;
    }

    public String getThrs() {
        return thrs;
    }

    public void setThrs(String thrs) {
        this.thrs = thrs;
    }

    public String getJbr() {
        return jbr;
    }

    public void setJbr(String jbr) {
        this.jbr = jbr;
    }

    public String getSfzhm() {
        return sfzhm;
    }

    public void setSfzhm(String sfzhm) {
        this.sfzhm = sfzhm;
    }

    public String getCars() {
        return cars;
    }

    public void setCars(String cars) {
        this.cars = cars;
    }

    public Boolean getDlkhxsd() {
        return dlkhxsd;
    }

    public void setDlkhxsd(Boolean dlkhxsd) {
        this.dlkhxsd = dlkhxsd;
    }

    public String getComType() {
        return comType;
    }

    public void setComType(String comType) {
        this.comType = comType;
    }

    public File getUpload() {
        return upload;
    }

    public void setUpload(File upload) {
        this.upload = upload;
    }

    public String getXhtbm() {
        return xhtbm;
    }

    public void setXhtbm(String xhtbm) {
        this.xhtbm = xhtbm;
    }

    public String getWjsdlf() {
        return wjsdlf;
    }

    public void setWjsdlf(String wjsdlf) {
        this.wjsdlf = wjsdlf;
    }

    public String getWjstx() {
        return wjstx;
    }

    public void setWjstx(String wjstx) {
        this.wjstx = wjstx;
    }

    public String getSumDlfTx() {
        return sumDlfTx;
    }

    public void setSumDlfTx(String sumDlfTx) {
        this.sumDlfTx = sumDlfTx;
    }

    public String getSfkIds() {
        return sfkIds;
    }

    public void setSfkIds(String sfkIds) {
        this.sfkIds = sfkIds;
    }

    public String getZjzyje() {
        return zjzyje;
    }

    public void setZjzyje(String zjzyje) {
        this.zjzyje = zjzyje;
    }

    public String getZjzff() {
        return zjzff;
    }

    public void setZjzff(String zjzff) {
        this.zjzff = zjzff;
    }

    public String getHttx() {
        return httx;
    }

    public void setHttx(String httx) {
        this.httx = httx;
    }

    public String getHtbmStr() {
        return htbmStr;
    }

    public void setHtbmStr(String htbmStr) {
        this.htbmStr = htbmStr;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public String getMonth() {
        return month;
    }

    public void setMonth(String month) {
        this.month = month;
    }

    public String getDay() {
        return day;
    }

    public void setDay(String day) {
        this.day = day;
    }

    public String getZh() {
        return zh;
    }

    public void setZh(String zh) {
        this.zh = zh;
    }

    public Boolean getBzjsfdlf() {
        return bzjsfdlf;
    }

    public void setBzjsfdlf(Boolean bzjsfdlf) {
        this.bzjsfdlf = bzjsfdlf;
    }

    public Boolean getSftg() {
        return sftg;
    }

    public void setSftg(Boolean sftg) {
        this.sftg = sftg;
    }

    public String getDqtxxx() {
        return dqtxxx;
    }

    public void setDqtxxx(String dqtxxx) {
        this.dqtxxx = dqtxxx;
    }

    public Cght getCght() {
        return cght;
    }

    public void setCght(Cght cght) {
        this.cght = cght;
    }

    public String getZdlf() {
        return zdlf;
    }

    public void setZdlf(String zdlf) {
        this.zdlf = zdlf;
    }

    public String getZtx() {
        return ztx;
    }

    public void setZtx(String ztx) {
        this.ztx = ztx;
    }


    public Double getHtce() {
        return htce;
    }

    public void setHtce(Double htce) {
        this.htce = htce;
    }

    public Boolean getSfkzdlf() {
        return sfkzdlf;
    }

    public void setSfkzdlf(Boolean sfkzdlf) {
        this.sfkzdlf = sfkzdlf;
    }

    @Autowired
    public void setXsdService(XsdService xsdService) {
        this.xsdService = xsdService;
    }

    @Autowired
    public void setGnczService(GnczService gnczService) {
        this.gnczService = gnczService;
    }

    @Autowired
    public void setXsdDao(XsdDao xsdDao) {
        this.xsdDao = xsdDao;
    }

    @Autowired
    public void setQyjgService(QyjgService qyjgService) {
        this.qyjgService = qyjgService;
    }

    @Autowired
    public void setCgdService(CgdService cgdService) {
        this.cgdService = cgdService;
    }

}
